package com.infinit.selfhelp.common.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.infinit.selfhelp.common.loading.CommonLoadingDelegate
import com.infinit.selfhelp.common.loading.ILoadingDelegate
import com.infinit.selfhelp.common.loading.LoadingDialogManager

abstract class BaseFragment : Fragment(), LoadingDialogManager {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initData()
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val createView = createView(inflater, container, savedInstanceState)
        initView()
        onEvent()
        return createView
    }

    abstract fun createView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View?

    abstract fun onEvent()
    open fun initData() {}
    open fun initView() {}

    override val loadingDelegate: ILoadingDelegate by lazy {
        CommonLoadingDelegate()
    }
}
